<template>
	<view class="video_content">
		<video id="myVideo" ref="video"  :autoplay="autoplay"  @click="click" :loop="true" class="video_player" :controls="false" :src="address"></video>
	</view>
</template>

<script>
	let timer = null
	export default {
		props:['address','autoplay'],
		data() {
			return {
				dbClick:false,
				play:false,
				videoContext:null
			};
		},
		created() {
			this.videoContext = uni.createVideoContext('myVideo',this)
			if(this.autoplay){
				this.play = true
			}
		},
		methods:{
			player(){
				this.videoContext.seek(0)
				this.videoContext.play()
				this.play = true
			},
			pause(){
				this.videoContext.pause()
			},
			replayer(){
				console.log(this.videoContext)
				this.videoContext.play()
			},
			click(){
				this.dbClick = !this.dbClick
				clearTimeout(timer)
				timer = setTimeout(()=>{
					if(this.dbClick){
						if(this.play){
							this.pause()
						}else{
							this.replayer()
						}
						this.play = !this.play
						this.dbClick = false
					}else{
						uni.$emit('dbClick')
					}
				},300)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.video_content,.video_player{
		width: 100%;
		height: 100%;
	}
</style>
